package advanced.comparator;

import java.util.Random;

public class Main {

	public static void main(String args[])
	{

		MyVector<Student> students = getStudents(100);
		
		//sort the students by name, from a to z
		students.sort(new StudentNameComparator());
		System.out.println(students.toString());
		
		//sort the students by id, from smaller id to larger id
		students.sort(new StudentIdComparator());
		System.out.println(students.toString());
		
		
	}
	
	//create size students in a vector
	public static MyVector<Student> getStudents(int size)
	{
		MyVector<Student> students = new MyVector<Student>();
		
		Random random = new Random();
		
		for(int i=0; i<size; i++)
		{
			students.add(new Student(generateRandomName(),10000+random.nextInt(99999) ) );
		}
		
		return students;
	}
	
	//generate a random name
	public static String generateRandomName()
	{
		String alphabet= "abcdefghijklmnopqrstuvwxyz";
		String name = "";
		Random random = new Random();
		int randomLen = 3+random.nextInt(10);
		for (int i = 0; i < randomLen; i++) {
		    char c = alphabet.charAt(random.nextInt(26));
		    name+=c;
		}
		
		return name;
	}
}
